﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class service_video : System.Web.UI.Page
{
    public string szjqL = "";     //实战技巧左
    public string szjqR = "";    //实战技巧右
    public string xsbk = "";     //新手必看
    public string yzln = "";     //赢在理念
    public string splb = "";     //视频列表
    public string neareastVideo = "";     //推荐视频

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            szjqL = SzjqL().ToString();
            szjqR = SzjqR().ToString();
            xsbk = Xsbk().ToString();
            yzln = Yzln().ToString();
            splb = Splb().ToString();
            neareastVideo = NeareastVideo().ToString();
        }
    }
    private Web_VedioBLL videoBll;
    /// <summary>
    /// 视频业务类
    /// </summary>
    private Web_VedioBLL VideoBll
    {
        get
        {
            if (videoBll == null)
            {
                videoBll = new Web_VedioBLL();
            }
            return videoBll;
        }
    }
    /// <summary>
    /// 最近的视频对象
    /// </summary>
    /// <returns></returns>
    protected StringBuilder NeareastVideo()
    {
        StringBuilder sbVideo = new StringBuilder();
        Web_video video = VideoBll.GetNeareastVideo();
        if (video == null)
        {
            sbVideo.AppendLine("<div class=\"rec_video_c_l\" id=\"player\">服务器忙，请重试</div>");
        }
        else
        {
            sbVideo.AppendLine("<div class=\"rec_video_c_l\" id=\"player\"><object width=\"320\" height=\"240\"><param name=\"movie\" value=\"" + video.V_url + "\"></param>");
            sbVideo.AppendLine("<param name=\"allowScriptAccess\" value=\"sameDomain\"></param>");
            sbVideo.AppendLine("<param name=\"wmode\" value=\"transparent\"></param>");
            sbVideo.AppendLine("<embed src=\"" + video.V_url + "\" type=\"application/x-shockwave-flash\" width=\"320\" height=\"240\" allowfullscreen=\"true\" wmode=\"transparent\" allowscriptaccess=\"always\"></embed></object></div>");
            sbVideo.AppendLine("<div class=\"rec_video_c_m\"><div class=\"marginTop5\"></div><span class=\"font14 font-weight gray_t\" id=\"video_serise\">" + video.V_title + "</span><br />");
            sbVideo.AppendLine("<span class=\"gray\" >讲师：</span><span id=\"teacher\">" + (video.Setup_user != "" ? video.Setup_user : "") + "</span><br />");
            sbVideo.AppendLine("<span class=\"gray\" >时间：</span><span id=\"ctime\">" + (video.Setup_date.ToString() != "" ? video.Setup_date.GetValueOrDefault().ToShortDateString() : "") + "</span><br />");
            sbVideo.AppendLine("<span class=\"gray\" >推荐：</span><span id=\"stars\">");
            for (int i = 0; i < video.V_star; i++)
            {
                sbVideo.AppendLine("<img src=\"images/ico_star.jpg\" />");
            }
            sbVideo.AppendLine("</span><div class=\"marginTop5\"></div>");
            sbVideo.AppendLine("<span class=\"font14 lh22\" id=\"mark\">" + video.V_remark + "</span>");
            sbVideo.AppendLine("<span id=\"look\"><a href=\"" + video.V_url + "\" target=\"_blank\" class=\"b font14\">[观看]</a></span></div>");
        }
        return sbVideo;
    }
    /// <summary>
    /// 实战技巧左
    /// </summary>
    protected StringBuilder SzjqL()
    {

        DataTable dt = VideoBll.Szjq;
        StringBuilder sbSzjq = new StringBuilder();
        if (dt == null)
        {
            sbSzjq.AppendLine("<li>服务器忙，请重试</a>");
        }
        else
        {
            for (int i = 0; i < dt.Rows.Count / 2; i++)
            {
                System.Data.DataRow sRow = dt.Rows[i];
                string sId = Convert.ToString(sRow["v_id"]);
                string sTitle = Convert.ToString(sRow["v_title"]);
                sbSzjq.Append("<li><a href='" + "videoroom.aspx?id=" + sId + "' target=\"_blank\">" + (sTitle.Length > 20 ? sTitle.Substring(0, 20) + "..." : sTitle) + "</a></li>\r\n");
                if (i == 9)
                {
                    break;
                }
            }
        }
        return sbSzjq;
    }

    /// <summary>
    /// 实战技巧右
    /// </summary>
    protected StringBuilder SzjqR()
    {

        DataTable dt = VideoBll.Szjq;
        StringBuilder sbSzjq = new StringBuilder();
        if (dt != null)
        {
            for (int i = dt.Rows.Count / 2; i < dt.Rows.Count; i++)
            {
                System.Data.DataRow sRow = dt.Rows[i];
                string sId = Convert.ToString(sRow["v_id"]);
                string sTitle = Convert.ToString(sRow["v_title"]);
                sbSzjq.Append("<li><a href='" + "videoroom.aspx?id=" + sId + "' target=\"_blank\">" + (sTitle.Length > 21 ? sTitle.Substring(0, 21) + "..." : sTitle) + "</a></li>\r\n");
                if (i == dt.Rows.Count / 2 + 9)
                {
                    break;
                }
            }
        }
        else
        {
            sbSzjq.AppendLine("<li>服务器忙，请重试</li>");
        }
        return sbSzjq;
    }

    /// <summary>
    /// 新手必看
    /// </summary>
    protected StringBuilder Xsbk()
    {
        StringBuilder sbXsbk = new StringBuilder();
        DataTable dt = VideoBll.Xsbk;
        if (dt != null)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                System.Data.DataRow sRow = dt.Rows[i];
                string sId = Convert.ToString(sRow["v_id"]);
                string sTitle = Convert.ToString(sRow["v_title"]);
                sbXsbk.Append("<li><a href='" + "videoroom.aspx?id=" + sId + "' target=\"_blank\">" + (sTitle.Length > 18 ? sTitle.Substring(0, 17) + "..." : sTitle) + "</a></li>\r\n");
            }
        }
        else
        {
            sbXsbk.AppendLine("");
        }
        return sbXsbk;
    }

    /// <summary>
    /// 赢在理念
    /// </summary>
    protected StringBuilder Yzln()
    {

        StringBuilder sbYzln = new StringBuilder();

        DataTable dt = VideoBll.Yzln;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            System.Data.DataRow sRow = dt.Rows[i];
            string sId = Convert.ToString(sRow["v_id"]);
            string sTitle = Convert.ToString(sRow["v_title"]);
            sbYzln.Append("<li><a href='" + "videoroom.aspx?id=" + sId + "' target=\"_blank\">" + (sTitle.Length > 19 ? sTitle.Substring(0, 19) + "..." : sTitle) + "</a></li>\r\n");
            if (i == 9)
            {
                break;
            }
        }
        return sbYzln;
    }

    /// <summary>
    /// 推荐视频列表
    /// </summary>
    protected StringBuilder Splb()
    {

        StringBuilder sbSplb = new StringBuilder();

        DataTable dt = VideoBll.Zxjc;     //需修改，未找到推荐视频列表  （终为推荐课程）
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            System.Data.DataRow sRow = dt.Rows[i];
            string sTitle = Convert.ToString(sRow["v_title"]);
            string url = Convert.ToString(sRow["V_url"]);
            string teacher = Convert.ToString(sRow["setup_user"]);
            string sum = Convert.ToString(sRow["v_remark"]);
            //string teacher = "";
            //string sum = "";
            DateTime date = Convert.ToDateTime(sRow["setup_date"]);
            //DateTime date = DateTime.Now;
            //int star = 1;
            int star = Convert.ToInt32(sRow["v_star"]);
            url = url.Substring(0, url.IndexOf("$"));
            sbSplb.Append("<li><a href=\"#\" star =\"" + (star > 0 ? star : 0) + "\"   date=\"" + (date.ToString() != "" ? date : DateTime.Now) + "\" sum=\"" + (sum != "" ? sum : "") + "\" teacher=\"" + (teacher != "" ? teacher : "") + "\" title=\"" + (sTitle != "" ? sTitle : "") + "\" url=\"" + url + "\" target=\"_blank\">" + (sTitle.Length > 19 ? sTitle.Substring(0, 19) + "..." : sTitle) + "</a></li>\r\n");
            if (i == 7)
            {
                break;
            }
        }
        return sbSplb;
    }
}